package com.armani.controller;

import com.alibaba.fastjson.JSON;
import com.armani.entity.ItemType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author lvzhenzhen
 * @Date 2021/11/25 6:48
 */
@Controller
@RequestMapping("/test")
public class TestController {
    /**
     * 接收单个参数
     * @param title-
     * @param id
     * @return
     */
    @RequestMapping(value = "/user.do", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String p1(@RequestParam String title,@RequestParam Integer id){
        ItemType user = new ItemType();
      user.setTitle(title);
       user.setId(id);
        return JSON.toJSONString(user);
    }

    /**
     * 接收多个相同参数

     * @return
     */
    @RequestMapping(value = "/aihao", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String aihao(@RequestParam String[] ah){

        return JSON.toJSONString(ah);
    }

    /**
     * 接收对象参数
     * @return
     */
    @RequestMapping(value = "/userobject", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String userobject(ItemType user){
        return JSON.toJSONString(user);
    }

    @RequestMapping(value = "/user2/{page}/{limit}", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String listSearch(@PathVariable Integer page, @PathVariable Integer limit){
        return "页码"+page+"分页"+limit;

    }

    @RequestMapping(value = "/json3", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String jsonData(@RequestBody ItemType user){
        return JSON.toJSONString(user);
    }


}
